﻿using System;
using RestSharp;
using Ymatou.API.Common;
using Ymatou.Evaluate.Buyer.Model.ApiModel.Response.Query;
using Ymatou.Evaluate.Buyer.Model.Dto;
using Ymatou.ServiceCenter;

namespace Ymatou.Evaluate.Buyer.Model.ApiModel.Request.Query
{
    /// <summary>
    /// 获取商品评价列表
    /// </summary>
    [Resource("bevaluateq.iapi.ymatou.com", "api/GetProdEvaluateList", Method.GET, ParameterBuildType.UrlQueryString)]
    public class GetProdEvaluateListRequest : BaseRequestModel<GetProdEvaluateListResponse>
    {
        public override string ApiName
        {
            get { return "api/GetProdEvaluateList"; }
        }

        public override bool HttpGet
        {
            get { return true; }
        }

        /// <summary>
        /// 商品Id
        /// </summary>
        public string ProductId { get; set; }

        /// <summary>
        /// 评价类型
        /// </summary>
        public EvaluateType EvalTp { get; set; }

        /// <summary>
        /// 分页索引
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页显示记录数
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 当前页最后一条评价的评价Id
        /// </summary>
        public int? LastProdEvalId { get; set; }

        /// <summary>
        /// 当前页最后一条评价的评价时间
        /// </summary>
        public long? LastEvalTime { get; set; }

        public override void Validate()
        {
            const string errCode = "-1";
            if (string.IsNullOrWhiteSpace(ProductId))
            {
                throw new BussniessException(errCode, "商品Id不能为空");
            }
            Guid guid;
            ProductId = ProductId.Trim();
            if (!Guid.TryParse(ProductId, out guid))
            {
                throw new BussniessException(errCode, "商品Id非法");
            }
            if ((LastProdEvalId.HasValue && !LastEvalTime.HasValue) ||
                (!LastProdEvalId.HasValue && LastEvalTime.HasValue))
            {
                throw new BussniessException(errCode, "当前页最后一条评价Id和评价时间必须同时传入");
            }
            if (PageIndex < 1)
            {
                throw new BussniessException(errCode, "PageIndex参数不正确，必须>=1");
            }
            if (PageSize < 1)
            {
                throw new BussniessException(errCode, "PageSize参数不正确，必须>=1");
            }
            base.Validate();
        }
    }
}